package org.anjoy.ktv;

import java.util.ArrayList;

import org.anjoy.ktv.adapter.SongNameAdapter;
import org.anjoy.ktv.adapter.StarAdapter;
import org.anjoy.ktv.bean.Song;
import org.anjoy.ktv.bean.Star;
import org.anjoy.ktv.util.KtvAlterDialog;
import org.anjoy.ktv.util.KtvAnimationDialog;
import org.anjoy.ktv.util.KtvBackgroundDialog;
import org.anjoy.ktv.util.KtvSelectDialog;
import org.anjoy.ktv.util.KtvSongPreviewDialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnKeyListener;
import android.content.DialogInterface.OnShowListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.Toast;

public class KTVActivity extends Activity {

	private ImageButton mainPageBtn;
	private ImageButton serviceBtn;
	private ImageButton atmosphereBtn;
	private ImageButton callBtn;
	private EditText scrollFontEdt;
	private ImageButton tuningBtn;
	private ImageButton muteBtn;
	private ImageButton volumeBarBtn;
	private ImageButton originalSingingBtn;
	private ImageButton reSingBtn;
	private ImageButton playBtn;
	private ImageButton nextSongBtn;
	private ImageButton chosenSongBtn;
	private EditText chosenSongEdt;
	private Context mContext;

	// songs
	private ArrayList<Song> songs;
	private GridView songGridView;

	// star
	private ArrayList<Star> stars;
	private GridView starGridView;
	
	//song top
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.ktv_main_page);
		mContext = this;
		initView();
		setSongGridViewData();
		//setStarGridViewData();
	}

	public void initView() {
		mainPageBtn = (ImageButton) findViewById(R.id.imgbtn_main_page);
		serviceBtn = (ImageButton) findViewById(R.id.imgbtn_service);
		atmosphereBtn = (ImageButton) findViewById(R.id.imgbtn_atmosphere);
		callBtn = (ImageButton) findViewById(R.id.imgbtn_call);
		scrollFontEdt = (EditText) findViewById(R.id.scroll_font);
		tuningBtn = (ImageButton) findViewById(R.id.imgbtn_tuning);
		muteBtn = (ImageButton) findViewById(R.id.imgbtn_mute);
		volumeBarBtn = (ImageButton) findViewById(R.id.imgbtn_volume_bar);
		originalSingingBtn = (ImageButton) findViewById(R.id.imgbtn_original_singing);
		reSingBtn = (ImageButton) findViewById(R.id.imgbtn_resing);
		playBtn = (ImageButton) findViewById(R.id.imgbtn_play);
		nextSongBtn = (ImageButton) findViewById(R.id.imgbtn_next_song);
		chosenSongBtn = (ImageButton) findViewById(R.id.imgbtn_chosen_song);
		chosenSongEdt = (EditText) findViewById(R.id.edt_chosen_song);

		// song
		songGridView = (GridView) findViewById(R.id.ktv_song_name_gv);

		// star
		//starGridView = (GridView) findViewById(R.id.ktv_star_gv);
		registListenEvent();
	}

	public void registListenEvent() {
		mainPageBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		serviceBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		atmosphereBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		callBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		tuningBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		muteBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		volumeBarBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		originalSingingBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		reSingBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		playBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		nextSongBtn.setOnClickListener(new imgbtnOnclickListenEvent());
		chosenSongBtn.setOnClickListener(new imgbtnOnclickListenEvent());
	}

	public void showKtvAlterDialog() {
		Dialog dialog = new KtvAlterDialog(mContext,
				R.style.Ktv_alter_dialog_style);
		dialog.show();
	}

	public void showKtvSelectDialog() {
		Dialog selectDialog = new KtvSelectDialog(mContext,
				R.style.Ktv_alter_dialog_style);
		Window win = selectDialog.getWindow();
		LayoutParams params = new LayoutParams();
		params.x = 0;// 设置x坐标
		params.y = 0;// 设置y坐标
		win.setAttributes(params);
		selectDialog.setCanceledOnTouchOutside(true);// 设置点击Dialog外部任意区域关闭Dialog
		selectDialog.show();
	}

	public void showKtvAnimationDialog() {
		KtvAnimationDialog animationDialog = new KtvAnimationDialog(mContext);
		animationDialog.showDialog(R.layout.ktv_dialog_animation_style, 85, 80);
	}

	public void showKtvBackgroundDialog() {
		KtvBackgroundDialog backgroundDialog = new KtvBackgroundDialog(
				mContext, R.style.Ktv_alter_background_style);
		backgroundDialog.show();
	}

	public void showKtvSongPreviewDialog() {
		KtvSongPreviewDialog songPreviewDialog = new KtvSongPreviewDialog(
				mContext, R.style.Ktv_alter_song_preview_style);
		songPreviewDialog.show();
	}

	public class imgbtnOnclickListenEvent implements OnClickListener {

		@Override
		public void onClick(View v) {
			String text = "";
			switch (v.getId()) {
			case R.id.imgbtn_main_page:
				text = "imgbtn_main_page";
				showKtvAlterDialog();
				break;
			case R.id.imgbtn_service:
				text = "imgbtn_service";
				break;
			case R.id.imgbtn_atmosphere:
				text = "imgbtn_atmosphere";
				break;
			case R.id.imgbtn_call:
				text = "imgbtn_call";
				showKtvSelectDialog();
				break;
			case R.id.imgbtn_tuning:
				text = "imgbtn_tuning";
				showKtvAnimationDialog();
				break;
			case R.id.imgbtn_mute:
				text = "imgbtn_mute";
				showKtvBackgroundDialog();
				break;
			case R.id.imgbtn_volume_bar:
				text = "imgbtn_volume_bar";
				break;
			case R.id.imgbtn_original_singing:
				text = "imgbtn_original_singing";
				showKtvSongPreviewDialog();
				break;
			case R.id.imgbtn_resing:
				text = "imgbtn_resing";
				break;
			case R.id.imgbtn_play:
				text = "imgbtn_play";
				break;
			case R.id.imgbtn_next_song:
				text = "imgbtn_next_song";
				break;
			case R.id.imgbtn_chosen_song:
				text = "imgbtn_chosen_song";
				break;
			default:
				text = "nothing";
				break;
			}
			Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();
		}
	}

	public void setSongGridViewData() {
		initSongInfo();
		SongNameAdapter songNameAdapter = new SongNameAdapter(this, songs);
		songGridView.setAdapter(songNameAdapter);
	}

	public void setStarGridViewData() {
		initStarInfo();
		StarAdapter starAdapter = new StarAdapter(this, stars);
		starGridView.setAdapter(starAdapter);
	}

	public void initSongInfo() {
		songs = new ArrayList<Song>();
		Song song = null;
		song = new Song("", "This is my Love", "张惠妹", "", "1", "", "",
				3, "", "");
		songs.add(song);
		song = new Song("", "Hand in Hand", "张惠妹", "", "2", "", "", 3,
				"", "");
		songs.add(song);
		song = new Song("", "Hello kety", "张惠妹", "", "3", "", "", 3,
				"", "");
		songs.add(song);
		song = new Song("", "听海", "张惠妹", "", "4", "", "", 3, "", "");
		songs.add(song);
		song = new Song("", "无与伦比的美丽", "苏打绿", "", "5", "", "", 3, "", "");
		songs.add(song);
		song = new Song("", "早点回家", "苏打绿", "", "6", "", "", 3, "", "");
		songs.add(song);
		song = new Song("", "他夏了夏天", "苏打绿", "", "7", "", "", 3, "", "");
		songs.add(song);
		song = new Song("", "挪威的森林", "伍佰", "", "3", "", "", 3, "", "");
		songs.add(song);
		song = new Song("", "Satisfied", "Jewel", "", "5", "", "", 3, "", "");
		songs.add(song);
	}

	public void initStarInfo() {
		stars = new ArrayList<Star>();
		Star star = null;
		star = new Star("", "张学友", "男", "", "", "", "", "", 1, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 2, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 3, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 4, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 5, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 6, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 7, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 8, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 9, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 10, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 11, "");
		stars.add(star);
		star = new Star("", "张学友", "男", "", "", "", "", "", 12, "");
		stars.add(star);
	}
}